<?php


abstract class BasesfTraitementMedicament extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $traitement_id;


	
	protected $medicament_id;


	
	protected $qte_posologie;


	
	protected $duree;


	
	protected $quantite;


	
	protected $id;

	
	protected $asfTraitement;

	
	protected $asfMedicament;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getTraitementId()
	{

		return $this->traitement_id;
	}

	
	public function getMedicamentId()
	{

		return $this->medicament_id;
	}

	
	public function getQtePosologie()
	{

		return $this->qte_posologie;
	}

	
	public function getDuree()
	{

		return $this->duree;
	}

	
	public function getQuantite()
	{

		return $this->quantite;
	}

	
	public function getId()
	{

		return $this->id;
	}

	
	public function setTraitementId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->traitement_id !== $v) {
			$this->traitement_id = $v;
			$this->modifiedColumns[] = sfTraitementMedicamentPeer::TRAITEMENT_ID;
		}

		if ($this->asfTraitement !== null && $this->asfTraitement->getId() !== $v) {
			$this->asfTraitement = null;
		}

	} 
	
	public function setMedicamentId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->medicament_id !== $v) {
			$this->medicament_id = $v;
			$this->modifiedColumns[] = sfTraitementMedicamentPeer::MEDICAMENT_ID;
		}

		if ($this->asfMedicament !== null && $this->asfMedicament->getId() !== $v) {
			$this->asfMedicament = null;
		}

	} 
	
	public function setQtePosologie($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->qte_posologie !== $v) {
			$this->qte_posologie = $v;
			$this->modifiedColumns[] = sfTraitementMedicamentPeer::QTE_POSOLOGIE;
		}

	} 
	
	public function setDuree($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->duree !== $v) {
			$this->duree = $v;
			$this->modifiedColumns[] = sfTraitementMedicamentPeer::DUREE;
		}

	} 
	
	public function setQuantite($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->quantite !== $v) {
			$this->quantite = $v;
			$this->modifiedColumns[] = sfTraitementMedicamentPeer::QUANTITE;
		}

	} 
	
	public function setId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = sfTraitementMedicamentPeer::ID;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->traitement_id = $rs->getInt($startcol + 0);

			$this->medicament_id = $rs->getInt($startcol + 1);

			$this->qte_posologie = $rs->getString($startcol + 2);

			$this->duree = $rs->getInt($startcol + 3);

			$this->quantite = $rs->getInt($startcol + 4);

			$this->id = $rs->getInt($startcol + 5);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 6; 
		} catch (Exception $e) {
			throw new PropelException("Error populating sfTraitementMedicament object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(sfTraitementMedicamentPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			sfTraitementMedicamentPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(sfTraitementMedicamentPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->asfTraitement !== null) {
				if ($this->asfTraitement->isModified()) {
					$affectedRows += $this->asfTraitement->save($con);
				}
				$this->setsfTraitement($this->asfTraitement);
			}

			if ($this->asfMedicament !== null) {
				if ($this->asfMedicament->isModified()) {
					$affectedRows += $this->asfMedicament->save($con);
				}
				$this->setsfMedicament($this->asfMedicament);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = sfTraitementMedicamentPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += sfTraitementMedicamentPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->asfTraitement !== null) {
				if (!$this->asfTraitement->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->asfTraitement->getValidationFailures());
				}
			}

			if ($this->asfMedicament !== null) {
				if (!$this->asfMedicament->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->asfMedicament->getValidationFailures());
				}
			}


			if (($retval = sfTraitementMedicamentPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = sfTraitementMedicamentPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getTraitementId();
				break;
			case 1:
				return $this->getMedicamentId();
				break;
			case 2:
				return $this->getQtePosologie();
				break;
			case 3:
				return $this->getDuree();
				break;
			case 4:
				return $this->getQuantite();
				break;
			case 5:
				return $this->getId();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = sfTraitementMedicamentPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getTraitementId(),
			$keys[1] => $this->getMedicamentId(),
			$keys[2] => $this->getQtePosologie(),
			$keys[3] => $this->getDuree(),
			$keys[4] => $this->getQuantite(),
			$keys[5] => $this->getId(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = sfTraitementMedicamentPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setTraitementId($value);
				break;
			case 1:
				$this->setMedicamentId($value);
				break;
			case 2:
				$this->setQtePosologie($value);
				break;
			case 3:
				$this->setDuree($value);
				break;
			case 4:
				$this->setQuantite($value);
				break;
			case 5:
				$this->setId($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = sfTraitementMedicamentPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setTraitementId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setMedicamentId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setQtePosologie($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setDuree($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setQuantite($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setId($arr[$keys[5]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(sfTraitementMedicamentPeer::DATABASE_NAME);

		if ($this->isColumnModified(sfTraitementMedicamentPeer::TRAITEMENT_ID)) $criteria->add(sfTraitementMedicamentPeer::TRAITEMENT_ID, $this->traitement_id);
		if ($this->isColumnModified(sfTraitementMedicamentPeer::MEDICAMENT_ID)) $criteria->add(sfTraitementMedicamentPeer::MEDICAMENT_ID, $this->medicament_id);
		if ($this->isColumnModified(sfTraitementMedicamentPeer::QTE_POSOLOGIE)) $criteria->add(sfTraitementMedicamentPeer::QTE_POSOLOGIE, $this->qte_posologie);
		if ($this->isColumnModified(sfTraitementMedicamentPeer::DUREE)) $criteria->add(sfTraitementMedicamentPeer::DUREE, $this->duree);
		if ($this->isColumnModified(sfTraitementMedicamentPeer::QUANTITE)) $criteria->add(sfTraitementMedicamentPeer::QUANTITE, $this->quantite);
		if ($this->isColumnModified(sfTraitementMedicamentPeer::ID)) $criteria->add(sfTraitementMedicamentPeer::ID, $this->id);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(sfTraitementMedicamentPeer::DATABASE_NAME);

		$criteria->add(sfTraitementMedicamentPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setTraitementId($this->traitement_id);

		$copyObj->setMedicamentId($this->medicament_id);

		$copyObj->setQtePosologie($this->qte_posologie);

		$copyObj->setDuree($this->duree);

		$copyObj->setQuantite($this->quantite);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new sfTraitementMedicamentPeer();
		}
		return self::$peer;
	}

	
	public function setsfTraitement($v)
	{


		if ($v === null) {
			$this->setTraitementId(NULL);
		} else {
			$this->setTraitementId($v->getId());
		}


		$this->asfTraitement = $v;
	}


	
	public function getsfTraitement($con = null)
	{
		if ($this->asfTraitement === null && ($this->traitement_id !== null)) {
						include_once 'lib/model/om/BasesfTraitementPeer.php';

			$this->asfTraitement = sfTraitementPeer::retrieveByPK($this->traitement_id, $con);

			
		}
		return $this->asfTraitement;
	}

	
	public function setsfMedicament($v)
	{


		if ($v === null) {
			$this->setMedicamentId(NULL);
		} else {
			$this->setMedicamentId($v->getId());
		}


		$this->asfMedicament = $v;
	}


	
	public function getsfMedicament($con = null)
	{
		if ($this->asfMedicament === null && ($this->medicament_id !== null)) {
						include_once 'lib/model/om/BasesfMedicamentPeer.php';

			$this->asfMedicament = sfMedicamentPeer::retrieveByPK($this->medicament_id, $con);

			
		}
		return $this->asfMedicament;
	}

} 